﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>分类管理</title>
    <link href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui.min.css" rel="stylesheet">
    <style type="text/css">
        .ms-controller {
            visibility: hidden;
        }
    </style>
</head>
<body ms-controller="vmCATE" class="ms-controller">
    <div class="sui-container" style="width:98%">
        <div class="sui-form form-horizontal sui-validate">

            <table class="sui-table table-primary table-zebra">
                <thead>
                    <tr>
                        <th>分类名称</th>
                        <!--<th>图片样式</th>-->
                        <th>排序</th>
                        <th ms-if="@InfoType==1&&@modelData.Lvl==1">通用/城市</th>
                        <th>显示</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ms-for="el in @ListData">
                        <td><input type="text" data-rules="required" ms-duplex="el.TypeName" class="input-large input-xfat" /></td>
                        <!--<td><input type="text" ms-duplex="el.ImgUrl" class="input-large input-xfat" /></td>-->
                        <td><input type="text" ms-duplex="el.Sort" style="width:50px;" class="input-large input-xfat" /></td>
                        <td ms-if="@InfoType==1&&el.Lvl==1">
                            <select ms-duplex="el.CType">
                                <option value="1">通用</option>
                                <option value="2">城市</option>
                            </select>
                        </td>
                        <td>
                            <span class='sui-text-success' ms-if="el.ISShow==1">显示</span>
                            <span class='sui-text-danger' ms-if="el.ISShow!=1">隐藏</span>
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="sui-btn btn-bordered btn-warning" style="margin:3px;" ms-click="@HideShow(el)"  >{{el.ISShow==1?'隐藏':'显示'}}</a>
                            <a href="javascript:void(0);" class="sui-btn btn-bordered btn-success" style="margin:3px;" ms-click="@saveitem(el)" ms-if="top.model.HasAuth('EDIT')" >保存</a>
                            <a href="javascript:void(0);" class="sui-btn btn-bordered btn-primary" style="margin:3px;" ms-click="@subitem(el)" ms-if="el.Lvl==1" >子分类</a>
                            <a href="javascript:void(0);" class="sui-btn btn-bordered btn-danger" ms-click="@delitem(el)" ms-if="top.model.HasAuth('DEL')">删除</a>

                        </td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr ms-if="top.model.HasAuth('ADD')">
                        <td><input type="text" data-rules="required" ms-duplex="@modelData.TypeName"  class="input-large input-xfat" /></td>
                        <!--<td><input type="text" ms-duplex="@modelData.TypeDesp" class="input-large input-xfat" /></td>-->
                        <td><input type="text" ms-duplex="@modelData.Sort" style="width:50px;"  class="input-large input-xfat" /></td>
                        <td ms-if="@InfoType==1&&@modelData.Lvl==1">
                            <select ms-duplex="@modelData.CType">
                                <option value="1">通用</option>
                                <option value="2">城市</option>
                            </select>
                        </td>
                        <td></td>
                        <td><a href="javascript:void(0);" class="sui-btn btn-primary" ms-click="@addsub()">添加</a></td>
                        
                    </tr>
                </tfoot>
            </table>
        </div>


    </div>


    <script type="text/javascript" src="http://g.alicdn.com/sj/lib/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="http://g.alicdn.com/sj/dpl/1.5.1/js/sui.min.js"></script>
    <script src="//cdn.bootcss.com/avalon.js/2.1.8/avalon.js"></script>
    <script src="/admin/js/layer/layer.js"></script>
    <script src="/admin/js/ComFunJS.js?v=20170808"></script>

    <script type="text/javascript">
        var model = avalon.define({
            $id: "vmCATE",
            ListData: [],
            InfoType: ComFunJS.getQueryString("infotype", "0"),
            modelData: { "ID": "0", "Client": ComFunJS.getQueryString("client", "0"), "InfoType": ComFunJS.getQueryString("infotype", "0"), "CType": "1", "TypeName": "", "TypeDesp": "", "LinkUrl": "", "ImgUrl": "", "Lvl": ComFunJS.getQueryString("lvl", "1"), "TopID": ComFunJS.getQueryString("TopID", "0"), "Sort": "1", "ISMsg": "0" },
            GetLIST: function () {
                $.getJSON("/adapi/base/cate/list/" + model.InfoType + "/" + model.modelData.TopID, function (r) {
                    model.ListData.clear();
                    if (r.error == "") {
                        model.ListData = r.result;
                        model.modelData.Sort = model.ListData.length + 1;
                    }

                })

            },
            subitem: function (el) {
                top.ComFunJS.winShowForm("/admin/LIST/cate.html?type=" + el.CType + "&TopID=" + el.ID + "&client=" + el.Client + "&infotype=" + el.InfoType + "&lvl=" + (el.Lvl + 1), el.TypeName);
            },
            addsub: function () {
                if (model.modelData.TypeName) {
                    var data = model.modelData.$model;
                    $.post("/adapi/base/cate/add", data, function (r) {
                        if (r.error == "") {
                            model.ListData.push(r.result);
                            model.modelData.Sort = model.ListData.length + 1;
                            model.modelData.TypeName = "";
                            model.modelData.TypeDesp = "";
                            model.modelData.LinkUrl = "";
                            model.modelData.ISMsg = "";
                        }

                    })
                }
            },
            saveitem: function (el) {
                if (el) {
                    var data = el.$model;
                    $.post("/adapi/base/cate/add", data, function (r) {
                        if (r.error == "") {
                            top.ComFunJS.winShowMsg("保存成功");
                        } else {
                            top.ComFunJS.winShowAlert(r.error);
                        }


                    })
                }

            },
            HideShow: function (el) {
                if (el) {
                    $.getJSON("/adapi/base/cate/hide/" + el.ID, function (r) {
                        if (r.error == "") {
                            el.ISShow = el.ISShow == 1 ? 0 : 1;
                            //top.ComFunJS.winShowMsg("保存成功");
                        } else {
                            top.ComFunJS.winShowAlert(r.error);
                        }


                    })
                }
            },
            delitem: function (el) {
                if (el) {
                    top.ComFunJS.winShowConfirm("<span style='color:red;'>确定要删除吗?<span>", function () {
                        $.getJSON("/adapi/base/cate/del/" + el.ID, function (r) {
                            if (r.error == "") {
                                top.ComFunJS.winShowMsg("操作成功");
                                model.ListData.remove(el);
                            } else {
                                top.ComFunJS.winShowAlert(r.error);
                            }
                        })

                    })
                }
            }
        })

        avalon.ready(function () {

           model.GetLIST();

        })

        //model.$watch("InfoType", function () {
        //    model.modelData.InfoType = model.InfoType;
        //    model.GetLIST();
        //})
    </script>
</body>
</html>
